package frontend.parser.syntaxtree;

import frontend.lexer.TKType;
import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.function.Consumer;

public class StmtNodeForIfElse extends StmtNode {
    public CondNode cond;
    public StmtNode ifStmt;
    public StmtNode elseStmt;

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        terConsumer.accept(new TerminalSymbol(TKType.IFTK));
        terConsumer.accept(new TerminalSymbol(TKType.LPARENT));

        cond.walk(terConsumer, nonTerConsumer);

        terConsumer.accept(new TerminalSymbol(TKType.RPARENT));

        ifStmt.walk(terConsumer, nonTerConsumer);

        if (elseStmt != null) {//有无else
            terConsumer.accept(new TerminalSymbol(TKType.ELSETK));
            elseStmt.walk(terConsumer, nonTerConsumer);
        }

        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }
}
